package io.github.hidroh.materialistic;

import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;

import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;

/*
* 最上层的activity的继承类，主要提供如下公共功能的实现：
* 1、通过配置项改变application的主题
* 2、开启谷歌的应用分析服务
* @TODO
* GA配置的研究
* */
public abstract class TrackableActivity extends ActionBarActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        if (PreferenceManager.getDefaultSharedPreferences(this)
                .getBoolean(getString(R.string.pref_dark_theme), false)) {
            setTheme(R.style.AppTheme_Dark);
        }
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.d("TracableActivityonstart","true");
        // Get tracker.
        Tracker t = ((AnalyticsSampleApp)getApplication()).getTracker(
                AnalyticsSampleApp.TrackerName.APP_TRACKER);

        // Set screen name.
        // Where path is a String representing the screen name.
        t.setScreenName("path-track");

        // Send a screen view.
        t.send(new HitBuilders.AppViewBuilder().build());
    }

    @Override
    protected void onStop() {
        GoogleAnalytics.getInstance(getApplication()).reportActivityStop(this);
        super.onStop();
    }
}
